package com.zy.cat.controller.dev.v1;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import javax.servlet.http.HttpServletRequest;

import com.zy.cat.entity.CatUserWelfareCentr;
import com.zy.cat.service.CatUserWelfareCentrService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zy.cat.common.annotation.CheckDevPermission;
import com.zy.cat.common.annotation.CheckingMD5;
import com.zy.cat.common.utils.DateAPIUtils;
import com.zy.cat.common.utils.DrawProportionUtil;
import com.zy.cat.common.utils.SpringContextUtil;
import com.zy.cat.common.utils.TJKUtils;
import com.zy.cat.dao.Dao;
import com.zy.cat.entity.app.resp.CatUserFeedbackHistoryResp;
import com.zy.cat.entity.dev.CatDevRegisterIncomeHistory;
import com.zy.cat.entity.dev.CatDevRegisterInfo;
import com.zy.cat.entity.dev.CatDevRelation;
import com.zy.cat.entity.dev.CatDevSignedBeansHistory;
import com.zy.cat.entity.dev.CatDevSignedHistory;
import com.zy.cat.entity.dev.CatDevUserInfo;
import com.zy.cat.entity.dev.CatDevUserTaskRecord;
import com.zy.cat.entity.dev.CatDevWeInfo;
import com.zy.cat.entity.dev.garden.CatUserTreeTask;
import com.zy.cat.entity.dev.repository.CatDevBeansConvertInfoRepository;
import com.zy.cat.entity.dev.repository.CatDevDeviceTokenRepository;
import com.zy.cat.entity.dev.repository.CatDevRegisterIncomeHistoryRepository;
import com.zy.cat.entity.dev.repository.CatDevRegisterInfoRepository;
import com.zy.cat.entity.dev.repository.CatDevRelationRepository;
import com.zy.cat.entity.dev.repository.CatDevRemitInfoRepository;
import com.zy.cat.entity.dev.repository.CatDevUserInfoRepository;
import com.zy.cat.entity.dev.repository.CatDevUserTaskConfigRepository;
import com.zy.cat.entity.dev.repository.CatDevUserTaskRecordRepository;
import com.zy.cat.entity.dev.resp.CatDevBeanVideoHistoryResp;
import com.zy.cat.entity.dev.resp.CatDevHCInviteInfoResp;
import com.zy.cat.entity.dev.resp.CatDevOrderResp;
import com.zy.cat.entity.dev.resp.CatDevRemitInfoResp;
import com.zy.cat.entity.dev.resp.CatDevRemitRecordResp;
import com.zy.cat.entity.dev.resp.CatDevSignedHistoryResp;
import com.zy.cat.entity.dev.resp.CatDevUserInfoResp;
import com.zy.cat.entity.dev.resp.CatDevWelfareInfoResp;
import com.zy.cat.entity.dev.resp.CatDevWelfareInfoResp.UserTaskData;
import com.zy.cat.entity.game.repository.CatDevSignedBeansHistoryRepository;
import com.zy.cat.entity.mall.resp.CatCashBonusHistoryResp;
import com.zy.cat.entity.resp.Pages;
import com.zy.cat.entity.resp.RSPE;
import com.zy.cat.entity.resp.ResultPage;
import com.zy.cat.service.CacheService;
import com.zy.cat.service.CatDevService;
import com.zy.cat.service.CatDevTreeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @info
 * @author Link
 * @date 2019-11-28 18:45
 */
@Slf4j
@RestController
@RequestMapping("/v1/user")
@Api(value = "9catDevUser", tags = { "9趣猫个人信息开放API" }, description = "9趣猫个人信息开放接口")
public class CatDevInfoController {

	@Autowired
	CatDevService catDevService;

	@Autowired
	CacheService cacheService;

	@Autowired
	CatDevUserInfoRepository userInfoRepository;

	@Autowired
	CatDevBeansConvertInfoRepository beansConvertInfoRepository;

	@Autowired
	CatDevRegisterIncomeHistoryRepository catDevRegisterIncomeHistoryRepository;
	
	@Autowired
	CatDevUserTaskConfigRepository catDevUserTaskConfigRepository;

	@Autowired
	Dao<CatDevSignedHistoryResp> signedHistoryRespDao;

	@Autowired
	CatDevSignedBeansHistoryRepository signedBeansHistoryRepository;

	@Autowired
	CatDevRemitInfoRepository catDevRemitInfoRepository;
	
	@Autowired
	CatDevUserTaskRecordRepository newUserTaskRecordRepository;

	@Autowired
	CatDevRegisterInfoRepository catDevRegisterInfoRepository;

	@Autowired
	CatDevRelationRepository catDevRelationRepository;

	@Autowired
	Dao<CatDevRemitRecordResp> catDevRemitRecordResp;

	@Autowired
	Dao<CatDevOrderResp> catDevOrderRespDao;

	@Autowired
	Dao<Integer> intDao;

	@Autowired
	Dao<CatDevHCInviteInfoResp> hcInviteInfoRespDao;
	
	@Autowired
	CatDevTreeService catDevTreeService;

	@Autowired
	CatUserWelfareCentrService catUserWelfareCentrService;

	@Autowired
	@Qualifier("redis8")
	RedisTemplate<String, String> redis8;

	@PostMapping("/ios/login")
	@ApiOperation(value = "9趣猫用户IOS登录信息验证,仅支持IOS账户认证", notes = "code:1.验证成功、0.失败", position = 1, consumes = "application/x-www-form-urlencoded", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "1", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "brand", value = "手机品牌", example = "Honer", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "model", value = "品牌型号", example = "HSF-001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "pindex", value = "页面请求位置 (0. 首页、1.我的个人中心)", example = "0", required = false, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "APP友盟渠道ID", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utype", value = "账户类型(0.九趣猫、1.淘淘集)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "第一次微信登录返回字段,用户账户绑定", example = "UID_39D970F3F2DFE55FE6BAC85B79633B24", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "userid", value = "IOS用户id", example = "001840.113eaac33a374d87abca658c0ad16236.0845", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "identityToken", value = "IOS用户JWT信息", example = "374d87abca658c0ad16236.0845", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "authorizationCode", value = "IOS用户授权信息", example = "c6c9bb845d81848c898eb628a3de8a650.0.nryuq.mLeR9o6rWtusk5Z7iIg9uA", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(utype_uuid_rtype_userid)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
//	@CheckingMD5(checkingStr = "utype_uuid_rtype_userid", MD5 = "token")
	public Object iosLogin(Integer pindex,Integer rtype, Integer utype, String brand, String model, String vscode, String cid,
			String imei, String imsi,String pid, String userid, String identityToken, String authorizationCode, String uuid,
			String token) {
		if (rtype == null || rtype != 1) {
			return new RSPE<Object>(-6, "仅支持IOS账户认证！");
		}
		if (utype == null) {
			return new RSPE<Object>(-2, "账户类型错误！");
		}
		if (StringUtils.isBlank(userid)) {
			return new RSPE<Object>(-3, "IOS用户id错误！");
		}
		if (StringUtils.isBlank(identityToken)) {
			return new RSPE<Object>(-4, "identityToken信息错误！");
		}
		if (StringUtils.isBlank(authorizationCode)) {
			return new RSPE<Object>(-5, "authorizationCode错误！");
		}

		Callable<RSPE<Object>> result = new Callable<RSPE<Object>>() {
			@Override
			public RSPE<Object> call() throws Exception {
				Object obj= catDevService.iosLoginValidate(pid,rtype, utype, brand, model, vscode, cid, imei,
						imsi, userid, identityToken, authorizationCode,pindex);
				if(obj==null) {
					return new RSPE<Object>(-6, "认证信息过期，请重试或联系技术！");
				}
				return new RSPE<Object>(obj);
			}
		};
		return result;
	}

	@PostMapping("/login")
	@ApiOperation(value = "9趣猫用户微信登录/注册", position = 1, consumes = "application/x-www-form-urlencoded", notes = "个人信息(基本信息+收入信息)", response = CatDevUserInfoResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "appId", value = "应用ID(0.九趣猫(默认)、1.淘淘集、2.一陶)", example = "0", required = false, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pindex", value = "页面请求位置 (0. 首页、1.我的个人中心)", example = "0", required = false, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "brand", value = "手机品牌", example = "Honer", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "model", value = "品牌型号", example = "HSF-001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "APP友盟渠道ID", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
//			@ApiImplicitParam(name = "nikename", value = "微信昵称", example = "春暖錵疏🚗", required = true, dataType = "String", paramType = "form"),
//			@ApiImplicitParam(name = "pid", value = "邀请人的PID(无为自注册)", example = "C85B79633B24", dataType = "String", paramType = "form"),
//			@ApiImplicitParam(name = "sex", value = "性别(0.女、1.男)", example = "1", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "code", value = "微信登录CODE", example = "UID_39D970F3F2DFE55FE6BAC85B79633B24", required = true, dataType = "String", paramType = "form"),
//			@ApiImplicitParam(name = "icon", value = "微信头像", example = "https://", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "userid", value = "IOS用户id,用户账户绑定", example = "001840.113eaac33a374d87abca658c0ad16236.0845" , dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(code_uuid_rtype_code_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "code_uuid_rtype_code", MD5 = "token")
	public Object login(String userid,Integer rtype,@RequestParam(required = false, defaultValue = "0") Integer appId, @RequestParam(required = false, defaultValue = "-1") Integer pindex,
			String brand, String model, String vscode, String cid, String imei, String imsi, String code, String uuid,
			String token) {
		final LocalDateTime startTime = LocalDateTime.now();

		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<CatDevUserInfoResp>(-7, "应用平台参数错误！");
		}
		if (pindex == null || pindex < -1 || pindex > 1) {
			return new RSPE<CatDevUserInfoResp>(-4, "页面位置参数错误！");
		}
		if (appId>2) {
			return new RSPE<CatDevUserInfoResp>(-5, "appId应用不存在！");
		}
//		if (StringUtils.isBlank(nikename)) {
//			return new RSPE<CatDevUserInfoResp>(-2, "微信昵称不能为空！");
//		}
		if (StringUtils.isBlank(code)) {
			return new RSPE<CatDevUserInfoResp>(-3, "微信CODE不能为空！");
		}
//		if (StringUtils.isBlank(icon)) {
//			return new RSPE<CatDevUserInfoResp>(-4, "微信icon不能为空！");
//		}
		// 868627040868490
//		if (imei.equals("864360034672728")) {
//			log.error("test code:"+code);
//			return new RSPE<CatDevUserInfoResp>(-3, "微信CODE不能为空！");
//		}
		CatDevWeInfo weInfo = cacheService.getWxInfoByCode(rtype,code, appId,vscode,cid);
		final LocalDateTime wxTime = LocalDateTime.now();
		Duration duration = Duration.between(startTime, wxTime);
		if (duration.getSeconds() > 6) {
			log.error("登录接口调用微信超时:" + duration.toMillis());
		}
		if (weInfo == null || StringUtils.isBlank(weInfo.getUnionid())) {
			return new RSPE<CatDevUserInfoResp>(-6, "获取微信授权信息失败！");
		}

		// 校验一部手机只能登录一个微信号
		String pattern = "\\d{15}|\\d{17}";
		// 判断imei是否符合校验规则
		if (!StringUtils.isBlank(imei) && imei.matches(pattern)) {
			List<CatDevRegisterInfo> list = catDevRegisterInfoRepository.findByImei(imei);
			if (list != null && list.size() > 0) {
				CatDevUserInfo devUserInfo = userInfoRepository.findByPid(list.get(0).getPid());
				// 如果为同设备号，且不是一个微信账号，直接按登录失败处理
				if (devUserInfo != null && !weInfo.getUnionid().equals(devUserInfo.getUnionid())) {
					return new RSPE<CatDevUserInfoResp>(-7, "一台设备只能登录一个账号");
				}
			}
		}

		Callable<RSPE<CatDevUserInfoResp>> result = new Callable<RSPE<CatDevUserInfoResp>>() {
			@Override
			public RSPE<CatDevUserInfoResp> call() throws Exception {
				CatDevUserInfoResp respDev = catDevService.login("",rtype, weInfo, vscode, brand, model, cid, imei, imsi,
						pindex);
				LocalDateTime endTime = LocalDateTime.now();
				Duration duration = Duration.between(startTime, endTime);
				if (duration.getSeconds() > 8) {
					log.error("登录接口超时:" + duration.toMillis());
				}
				if (respDev == null) {
					return new RSPE<CatDevUserInfoResp>(-10, "登录失败！请联系客服人员！");
				}
				if (!StringUtils.isEmpty(respDev.getMsg())) {
					return new RSPE<CatDevUserInfoResp>(respDev.getMsg(), respDev);
				}
				return new RSPE<CatDevUserInfoResp>(respDev);
			}
		};
		return result;
	}

	@PostMapping("/info")
	@ApiOperation(value = "9趣猫用户个人信息", consumes = "application/x-www-form-urlencoded", position = 2, notes = "用于每次自动登录后获取用户的信息", response = CatDevUserInfoResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "UID_39D970F3F2DFE55FE6BAC85B79633B24", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "pindex", value = "页面请求位置 (0. 首页、1.我的个人中心)", example = "0", required = false, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "10511", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "101", required = false, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "渠道号", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_pid_utoken_pid_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_uuid_pid_utoken_pid", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object info(Integer rtype, String pid, @RequestParam(required = false, defaultValue = "-1") Integer pindex,
			String uuid, String utoken, @RequestParam(required = false, defaultValue = "") String vscode,
			@RequestParam(required = false, defaultValue = "") String cid, String token, HttpServletRequest request) {
		final LocalDateTime startTime = LocalDateTime.now();
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
		if (zdev == null || (StringUtils.isBlank(zdev.getUnionid())&&StringUtils.isBlank(zdev.getUserid()))) {
			return new RSPE<CatDevUserInfoResp>(-2, "此用户未注册");
		}
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<CatDevUserInfoResp>(-3, "应用平台参数错误！");
		}
		if (rtype == null || pindex < -1 || pindex > 1) {
			return new RSPE<CatDevUserInfoResp>(-4, "页面位置参数错误！");
		}

		Callable<RSPE<CatDevUserInfoResp>> result = new Callable<RSPE<CatDevUserInfoResp>>() {
			@Override
			public RSPE<CatDevUserInfoResp> call() throws Exception {
				RSPE<CatDevUserInfoResp> rspe = new RSPE<CatDevUserInfoResp>(
						catDevService.info(rtype, zdev,  pindex, vscode, cid));
				LocalDateTime endTime = LocalDateTime.now();
				Duration duration = Duration.between(startTime, endTime);
				if (duration.getSeconds() > 2) {
					log.error("个人信息接口超时:" + duration.toMillis());
				}
				return rspe;
			}
		};
		return result;
	}

	@PostMapping("/upd/sex")
	@ApiOperation(value = "9趣猫用户修改性别", consumes = "application/x-www-form-urlencoded", position = 2, notes = "用于每次自动登录后获取用户的信息", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "UID_39D970F3F2DFE55FE6BAC85B79633B24", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "sex", value = "性别(0.女、1.男)", example = "1", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_sex_pid_utoken_pid_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_uuid_sex_pid_utoken_pid", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object updSex(Integer rtype, Integer sex, String pid, String uuid, String utoken, String token) {

		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		if (sex == null || (sex != 0 && sex != 1)) {
			return new RSPE<Boolean>(-3, "性别参数错误！");
		}
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
		if (zdev == null || StringUtils.isBlank(zdev.getPid()) || (StringUtils.isBlank(zdev.getUnionid())&&StringUtils.isBlank(zdev.getUserid()))) {
			return new RSPE<Boolean>(-4, "此用户未注册");
		}

		Callable<RSPE<Boolean>> result = new Callable<RSPE<Boolean>>() {
			@Override
			public RSPE<Boolean> call() throws Exception {
				Boolean isOk = catDevService.updSex(zdev, rtype, pid, sex);
				if (isOk != null) {
					return new RSPE<Boolean>(isOk);
				}
				return new RSPE<Boolean>(false);
			}
		};
		return result;
	}

	@PostMapping("/upd/phone")
	@ApiOperation(value = "9趣猫用户绑定手机号码", consumes = "application/x-www-form-urlencoded", position = 4, notes = "九趣猫绑定手机号码", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "UID_39D970F3F2DFE55FE6BAC85B79633B24", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "phone", value = "手机号码", example = "13854108888", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "code", value = "验证码", example = "1111", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = false, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_phone_code_utoken_pid_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_uuid_phone_code_utoken_pid", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object updPhone(Integer rtype, String phone,String vscode, String code, String pid, String uuid, String utoken,
			String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		if (phone == null || phone.length() != 11) {
			return new RSPE<Boolean>(-3, "手机号码错误！");
		}
		if (StringUtils.isBlank(code)) {
			return new RSPE<Boolean>(-4, "验证码不能为空！");
		}

		/* 1.判定验证码是否正确 */
		String key = "CAT_BING_PHONE" + "_" + phone + "_" + code;
		if (!redis8.hasKey(key)) {
			return new RSPE<Boolean>(-6, "验证码错误！");
		}
		/* 2.判定手机号是否已经绑定 */
		CatDevUserInfo zdevByPhone = catDevService.getCatDevUserInfoByPhone(phone);

		CatDevUserInfo dev = catDevService.getCatDevUserInfoByPid(pid);

		if (zdevByPhone != null && !zdevByPhone.getPid().equals(pid)
				&& !zdevByPhone.getUnionid().equals(dev.getUnionid())) {
			return new RSPE<Boolean>(-5, "此手机号已被其他账号绑定");
		}

		/* 3.判定用户是否重复绑定手机号 */
		if (StringUtils.isNotBlank(dev.getPhone()) && dev.getPhone().equals(phone)) {
			return new RSPE<Boolean>(-7, "已绑定此手机号,请勿重复绑定");
		}

		Callable<RSPE<UserTaskData>> result = new Callable<RSPE<UserTaskData>>() {
			@Override
			public RSPE<UserTaskData> call() throws Exception {
				UserTaskData data = catDevService.updPhone(rtype, dev, pid, phone);
				if (data != null) {
					if (SpringContextUtil.isProd()) {
						redis8.delete(key);
					}
					if (rtype==1 && StringUtils.isEmpty(vscode)) {
						return new RSPE<UserTaskData>(1, "绑定成功！");
					}
					return new RSPE<UserTaskData>(1, "绑定成功！",data);
				}
				return new RSPE<UserTaskData>(0, "绑定失败！");
			}
		};
		return result;
	}

	@PostMapping("/upd/info")
	@ApiOperation(value = "9趣猫用户修改用户名和头像", consumes = "application/x-www-form-urlencoded", position = 4, notes = "", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "UID_39D970F3F2DFE55FE6BAC85B79633B24", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "icon", value = "头像地址(上传图片完成之后返回的地址)https://", example = "1", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "nikename", value = "用户昵称", example = "春暖錵疏🚗", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_uuid_utoken_pid_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_uuid_uuid_utoken_pid", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object updInfo(Integer rtype, String pid, String icon, String nikename, String uuid, String utoken,
			String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		if ((StringUtils.isBlank(icon) || !icon.startsWith("http")) || StringUtils.isBlank(nikename)) {
			return new RSPE<Boolean>(-3, "更改信息格式错误！");
		}
		if (nikename.length() > 10) {
			return new RSPE<Boolean>(-4, "此昵称过长，长度不能超过12个字符！");
		}
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
		if (zdev == null || (StringUtils.isBlank(zdev.getUnionid())&&StringUtils.isBlank(zdev.getUserid()))) {
			return new RSPE<Boolean>(-4, "此用户未注册");
		}
		Callable<RSPE<Boolean>> result = new Callable<RSPE<Boolean>>() {
			@Override
			public RSPE<Boolean> call() throws Exception {
				if (catDevService.updInfo(rtype, zdev, pid, icon, nikename)) {
					return new RSPE<Boolean>(1, "修改成功！");
				}
				return new RSPE<Boolean>(-1, "修改失败！");
			}
		};
		return result;
	}

	@PostMapping("/remit/list")
	@ApiOperation(value = "9趣猫用户提现历史记录", position = 5, notes = "9趣猫用户历史提现数据查询", consumes = "application/x-www-form-urlencoded", response = CatDevRemitRecordResp.class, responseContainer = "List")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "5380881829", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "mode", value = "提现方式（0.正常提款(含新用户及大额提现)、1.正常邀请提现、2.互拆邀请提现、4.订单返利提现、10.全部记录）", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_pid_mode_utoken_time)", example = "1001", required = true, dataType = "String", paramType = "form") })
	@CheckDevPermission
	@CheckingMD5(checkingStr = "rtype_uuid_pid_mode_utoken", MD5 = "token", checkSingle = true)
	public Object remitList(Integer rtype, Integer mode, String pid, String uuid, String utoken, String token,
			Pages pages) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		if (mode == null || Arrays.binarySearch(new int[] { 0, 1, 2,4, 10 }, mode) < 0) {
			return new RSPE<Object>(-3, "提现方式参数错误！");
		}
		Callable<RSPE<ResultPage<CatDevRemitRecordResp>>> result = new Callable<RSPE<ResultPage<CatDevRemitRecordResp>>>() {
			@Override
			public RSPE<ResultPage<CatDevRemitRecordResp>> call() throws Exception {
				return new RSPE<ResultPage<CatDevRemitRecordResp>>(catDevService.remitList(pid, pages, mode));

			}
		};
		return result;
	}

	@PostMapping("/remit")
	@ApiOperation(value = "9趣猫用户请求提现", position = 6, notes = "支付宝必须绑定后才能提款，每日仅能提现一次", consumes = "application/x-www-form-urlencoded", response = CatDevRemitRecordResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "5380881829", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "qtype", value = "取款类型（0.微信、1.支付宝）", example = "0", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "tmoney", value = "提款金额(0.新用户快速1元提现、1.1元提现、3.3元提现、8.8元提现、30.30元提现、50.50元提现)", example = "100", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_pid_utoken_tmoney_qtype_utoken_time)", example = "1001", required = true, dataType = "String", paramType = "form") })
	@CheckDevPermission
	@CheckingMD5(checkingStr = "rtype_uuid_pid_utoken_tmoney_qtype_utoken", MD5 = "token", checkSingle = true)
	public Object remit(Integer rtype, String pid, Integer qtype, Integer tmoney, String uuid, String utoken,
			String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		if (qtype == null || qtype < 0 || qtype > 1) {
			return new RSPE<Boolean>(-4, "取款类型不符合规范！");
		}

		if (tmoney == null || Arrays.binarySearch(new int[] { 0, 1, 3, 8, 30, 50 }, tmoney.intValue()) < 0) {
			return new RSPE<Boolean>(-5, "提款金额不符合规范！");
		}

		/* 查看用户微信绑定信息 */
		CatDevUserInfoResp dev = cacheService.getCatDevUserLoginInfo(pid);
		if (dev == null) {
			return new RSPE<Boolean>(-7, "提款用户未不存在！");
		}
		if (qtype == 1) {
			return new RSPE<Boolean>(-20, "暂不支持支付宝提现！");
		}
		// 当取款类型为支付宝时判断是否已绑定支付宝
		if (qtype == 1 && (StringUtils.equals(dev.getZaccount(), "-") || StringUtils.equals(dev.getZrealname(), "-"))) {
			return new RSPE<Boolean>(-6, "未绑定支付宝账号！");
		}

		/* 查看今日是否提现 */
		boolean isRemit = cacheService.getTodayCatDevRemitInfoResp(pid, 0, 3);
		if (isRemit) {
			return new RSPE<Boolean>(-3, "每日仅能提现一次！");
		}

		if (tmoney * 100 > cacheService.getCatDevLastRMB(pid)) {
			return new RSPE<Boolean>(-8, "提现金额必须小于或等于账户可提现金额！");
		}

		/* 判断是否关注公众号 */
		Integer isFocusWeChat = catDevService.getIsFocusWeChat(rtype, pid,
				catDevService.getCatDevUserInfoByPid(pid).getUnionid());
		if (qtype == 0 && isFocusWeChat == 0) {
			return new RSPE<CatDevRemitRecordResp>(-12, "未关注公众号,请先关注九趣猫公众号！");
		}

		// 判断账号是否异常
		if (dev.getUtype() == -1) {
			// 用户类型为异常用户无法正常提现
			return new RSPE<CatDevRemitRecordResp>(-19, "账号行为异常无法提现");
		}

		/* 一如果为快速提现判断连续签到天数 */
		if (tmoney == 1 || tmoney == 3 || tmoney == 8) {
			CatDevSignedHistoryResp historyResp = signedHistoryRespDao.selectOne(new CatDevSignedHistory(pid),
					"getSignInNumberDays");

			int days1 = 5, days3 = 11, days8 = 20;
			if (tmoney == 1 && historyResp.getSigns() < days1) {
				// 判断是否满足条件
				return new RSPE<CatDevRemitRecordResp>(-9, "未达到连续签到天数！");
			} else if (tmoney == 3 && historyResp.getSigns() < days3) {
				return new RSPE<CatDevRemitRecordResp>(-9, "未达到连续签到天数！");
			} else if (tmoney == 8 && historyResp.getSigns() < days8) {
				return new RSPE<CatDevRemitRecordResp>(-9, "未达到连续签到天数！");
			}

			// 查询用户提现总次数
			int remitCount = catDevRemitInfoRepository.countByPidAndRtypeInAndTstatusNot(pid, Arrays.asList(0), -1);
			// 如果用户正常提现次数大于3次，判断游戏情况
			if (remitCount > 3 || tmoney == 3 || tmoney == 8) {
				// 判断该用户从游戏内获取的现金豆数
				long catDevBeansByGame = cacheService.getCatDevBeansByGame(pid);
				// 如果为进行游戏，则直接返回账号异常
				if (catDevBeansByGame == 0) {
					return new RSPE<CatDevRemitRecordResp>(-19, "账号行为异常！");
				}
			}

			// 判断近期广告行为与PV是否正常
			Boolean isOk = cacheService.isNormalCatUser(rtype, pid, 1);
			if (!isOk) {
				return new RSPE<CatDevRemitRecordResp>(-19, "账号行为异常无法提现！");
			}

		} else if (tmoney == 30 || tmoney == 50) {
			// 判断账户认证审核状态
			if (dev.getFstatus() == 0) {
				return new RSPE<CatDevRemitRecordResp>(-10, "未进行实名认证，请先进行实名认证！");
			} else if (dev.getFstatus() == 1) {
				return new RSPE<CatDevRemitRecordResp>(-14, "正在审核实名认证信息！");
			} else if (dev.getFstatus() == -1) {
				// 查询审核失败原因
				CatDevUserInfo info = catDevService.getCatDevUserInfoByPid(pid);
				return new RSPE<CatDevRemitRecordResp>(-15, info.getInfo());
			}
			// 判断是否绑定手机号
			if (StringUtils.isBlank(dev.getPhone())) {
				return new RSPE<CatDevRemitRecordResp>(-21, "提现需进行手机号绑定，请先进行手机号绑定！");
			}
			// 判断近期广告行为与PV是否正常
//			Boolean isOk=cacheService.isNormalCatUser(rtype,pid,1);
//			if (!isOk) {
//				return new RSPE<CatDevRemitRecordResp>(-19, "账号行为异常无法提现！");
//			}
		} else if (tmoney == 0) {
			// 新用户可享1元极速提现，判断是否为新用户
			int count = catDevRemitInfoRepository.countByPidAndRtypeInAndTstatusNot(pid, Arrays.asList(3), -1);
			if (count > 0) {
				return new RSPE<CatDevRemitRecordResp>(-11, "非首次提现不再享有1元体验提现！");
			}
			CatDevUserInfo userInfo = catDevService.getCatDevUserInfoByPid(pid);
			boolean isErrorUser = userInfo.getCtime().contains("2020-02-03")
					|| userInfo.getCtime().contains("2020-02-04");
			// 判断是否为新用户,不为新用户则不能提现，并且不是2.3-2.4号注册的异常用户
			if (dev.getUtype() == 1 && !isErrorUser) {
				return new RSPE<CatDevRemitRecordResp>(-13, "非新用户不再享有1元体验提现！");
			}

			// 针对2.3~2.4号异常用户限制任务为1天
			if (isErrorUser) {
				// 如果为异常时期注册进来的用户，新手任务无时间限制
//				if(TJKUtils.parse2LocalDateTime("2020-02-07 10:00:00").plusDays(1).isBefore(LocalDateTime.now())) {
//					return new RSPE<CatDevRemitRecordResp>(-18, "新用户任务已过期！");
//				}
			} else if (TJKUtils.parse2LocalDateTime(userInfo.getCtime()).plusDays(7).isBefore(LocalDateTime.now())) {
				// 判断新人活动是否已过期，是否已注册七天
				return new RSPE<CatDevRemitRecordResp>(-18, "新用户任务已过期！");
			} else {
				// 判断是否存在邀请人,如果有邀请关系则不能提现
				// 如果存在邀请关系也不显示,新人任务
				CatDevRelation inviteInfo = cacheService.getInviteRelationByPid(pid);
				if (inviteInfo != null) {
					return new RSPE<CatDevRemitRecordResp>(-30, "被邀请用户无新人提现！");
				}
			}
			// 判断是否已完成新人任务
			long beans = cacheService.getCatDevBeansByGame(pid);
			if (beans < DrawProportionUtil.NEW_USER_TASK_BAENS_NUM) {
				return new RSPE<CatDevRemitRecordResp>(-17, "未完成新人任务无法提现！");
			}
		} else {
			return new RSPE<CatDevRemitRecordResp>(-16, "金额参数非法！");
		}

		Callable<RSPE<CatDevRemitRecordResp>> result = new Callable<RSPE<CatDevRemitRecordResp>>() {
			@Override
			public RSPE<CatDevRemitRecordResp> call() throws Exception {

				CatDevRemitRecordResp remit = catDevService.remit(rtype,1, pid, qtype, tmoney == 0 ? 3 : 0,
						dev.getZaccount(), dev.getZrealname(), tmoney * 100);
				if (remit != null) {
					return new RSPE<CatDevRemitRecordResp>(remit);
				}
				return new RSPE<CatDevRemitRecordResp>(0, "提现失败");
			}
		};
		return result;
	}
	
	@PostMapping("/bean/remit")
	@ApiOperation(value = "现金豆兑换提现", position = 6, notes = "新版本现金豆提现接口", consumes = "application/x-www-form-urlencoded", response = CatDevRemitRecordResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "appId", value = "应用标识(0.九趣猫、1.淘淘集)", example = "0", required = false, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "5380881829", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "beanNum", value = "提现现金豆数量(3000、20000、50000)", example = "3000", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_pid_utoken_beaNum_utoken_time)", example = "1001", required = true, dataType = "String", paramType = "form") })
	@CheckDevPermission
	@CheckingMD5(checkingStr = "rtype_uuid_pid_utoken_beanNum_utoken", MD5 = "token", checkSingle = true)
	public Object beanRemit(Integer rtype,@RequestParam(required = false,defaultValue = "0") Integer appId, String pid, Integer beanNum, String uuid, String utoken,
			String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		if (beanNum == null || Arrays.binarySearch(new int[] { 3000, 20000,50000}, beanNum.intValue()) < 0) {
			return new RSPE<Boolean>(-5, "提款金额不符合规范！");
		}

		/* 查看用户微信绑定信息 */
		CatDevUserInfoResp dev = cacheService.getCatDevUserLoginInfo(pid);
		if (dev == null) {
			return new RSPE<Boolean>(-7, "用户不存在！");
		}

		// 判断账号是否异常
		if (dev.getUtype() == -1) {
			// 用户类型为异常用户无法正常提现
			return new RSPE<CatDevRemitRecordResp>(-19, "账号行为异常无法提现");
		}

		//将现金豆转成现金(分)
		long tmoney=beanNum/100;
		//校验提现金额
		if(cacheService.getCatDevLastBeans(pid)/100.0<tmoney) {
			//如果计算上现金豆自动转换还不够，则返回无法提现
			return new RSPE<Boolean>(-8, "提现金额不足！");
		}
		// 新用户可享0.3元极速提现，判断是否为新用户
		int count = catDevRemitInfoRepository.countByPidAndRtypeInAndTstatusNot(pid, Arrays.asList(3), -1);
		// 判断是否有一元提现提现记录，如果有则判断是否已过期新手任务
		int mode=count > 0?0:3;
		Callable<RSPE<CatDevRemitRecordResp>> result = new Callable<RSPE<CatDevRemitRecordResp>>() {
			@Override
			public RSPE<CatDevRemitRecordResp> call() throws Exception {
				CatDevRemitRecordResp remit = catDevService.beanRemit(rtype,appId, pid, tmoney, beanNum,mode);
				if (remit != null) {
					return new RSPE<CatDevRemitRecordResp>(remit);
				}
				return new RSPE<CatDevRemitRecordResp>(0, "提现失败");
			}
		};
		return result;
	}
	
	@PostMapping("/order/rebate/remit")
	@ApiOperation(value = "用户订单返利提现", position = 6, notes = "用户订单返利提现,绑定微信公众号可提", consumes = "application/x-www-form-urlencoded", response = CatDevRemitRecordResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "5380881829", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "qtype", value = "取款类型（0.微信、1.支付宝）", example = "0", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "appId", value = "应用标识(0.九趣猫、1.淘淘集)", example = "0", required = false, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "tmoney", value = "提款金额(分)", example = "100", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_pid_tmoney_qtype_utoken_time)", example = "1001", required = true, dataType = "String", paramType = "form") })
	@CheckDevPermission
	@CheckingMD5(checkingStr = "rtype_uuid_pid_tmoney_qtype_utoken", MD5 = "token", checkSingle = true)
	public Object orderRebateremit(Integer rtype,@RequestParam(required = false,defaultValue = "0") Integer appId, String pid, Integer qtype, Integer tmoney, String uuid, String utoken,
			String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		if (qtype == null || qtype < 0 || qtype > 1) {
			return new RSPE<Boolean>(-4, "取款类型不符合规范！");
		}

		if (tmoney == null || tmoney <= 0) {
			return new RSPE<Boolean>(-5, "提款金额不符合规范！");
		}

		/* 查看用户微信绑定信息 */
		CatDevUserInfoResp dev = cacheService.getCatDevUserLoginInfo(pid);
		if (dev == null) {
			return new RSPE<Boolean>(-7, "提款用户未不存在！");
		}
		if (qtype == 1) {
			return new RSPE<Boolean>(-20, "暂不支持支付宝提现！");
		}
		// 当取款类型为支付宝时判断是否已绑定支付宝
		if (qtype == 1 && (StringUtils.equals(dev.getZaccount(), "-") || StringUtils.equals(dev.getZrealname(), "-"))) {
			return new RSPE<Boolean>(-6, "未绑定支付宝账号！");
		}

		if (tmoney > cacheService.getUserBalance(pid).getOrderRebate()) {
			return new RSPE<Boolean>(-8, "提现金额超出账户可提现余额！");
		}

		/* 判断是否关注公众号 */
		Integer isFocusWeChat = catDevService.getIsFocusWeChat(rtype, pid,
				catDevService.getCatDevUserInfoByPid(pid).getUnionid());
		if (qtype == 0 && isFocusWeChat == 0) {
			return new RSPE<CatDevRemitRecordResp>(-12, "未关注公众号,请先关注九趣猫公众号！");
		}
		
		if (tmoney < 30) {
			return new RSPE<Boolean>(-40, "提款金额不能小于0.3元！");
		}


		Callable<RSPE<CatDevRemitRecordResp>> result = new Callable<RSPE<CatDevRemitRecordResp>>() {
			@Override
			public RSPE<CatDevRemitRecordResp> call() throws Exception {

				CatDevRemitRecordResp remit = catDevService.remit(rtype,appId, pid, qtype, 4,
						dev.getZaccount(), dev.getZrealname(), tmoney);
				if (remit != null) {
					return new RSPE<CatDevRemitRecordResp>(remit);
				}
				return new RSPE<CatDevRemitRecordResp>(0, "提现失败");
			}
		};
		return result;
	}

	@PostMapping("/beans/convert")
	@ApiOperation(value = "9趣猫用户请求现金豆兑换", position = 7, notes = "1W=1元", consumes = "application/x-www-form-urlencoded", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "5380881829", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "beans", value = "兑换金豆(只能是1W的整倍数)", example = "10000", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_pid_utoken_beans_utoken_time)", example = "1001", required = true, dataType = "String", paramType = "form") })
	@CheckDevPermission
	@CheckingMD5(checkingStr = "rtype_uuid_pid_utoken_beans_utoken", MD5 = "token", checkSingle = true)
	public Object beansConvert(Integer rtype, String pid, Long beans, String uuid, String utoken, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		// 用户财务状态判断
		if (catDevService.getCatDevUserFstatus(pid) == -1) {
			return new RSPE<Boolean>(-3, "用户财务信息状态异常，请联系客服处理！");
		}
		if (beans == null || beans % 10000 != 0) {
			return new RSPE<Boolean>(-3, "兑换金豆不符合规范！");
		}
		if (beansConvertInfoRepository.findByPidAndCtime(pid, TJKUtils.DateTime(TJKUtils.YYYY_MM_DD)) != null) {
			return new RSPE<Boolean>(-4, "今日已兑换过,请明天再进行兑换！");
		}
		/* 需要加上用户现金豆数量的校验,如果该用户的现金豆总数小于当前传入的beans数则直接提示返回 */
		if (cacheService.getCatDevLastBeans(pid) < beans) {
			return new RSPE<Boolean>(-3, "现金豆不足！");
		}
		Callable<RSPE<Boolean>> result = new Callable<RSPE<Boolean>>() {
			@Override
			public RSPE<Boolean> call() throws Exception {
				return new RSPE<Boolean>(catDevService.beansConvert(rtype, pid, beans));
			}
		};
		return result;
	}

	@PostMapping("/get/tburl")
	@ApiOperation(value = "9趣猫/淘淘集用户申请淘宝授权", position = 8, notes = "获取淘宝授权H5链接，用于自动填单,webView打开并成功授权后会自动回调客户端代码catTbOAuth2.callback(status,data)[status(0.授权失败、1.授权成功),data(返回授权信息)],客户端提示并关闭webView", consumes = "application/x-www-form-urlencoded", response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "系统平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "ctype", value = "应用平台(0.九趣猫、1.淘淘集、2.一陶)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "5380881829", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_utoken_pid_time)", example = "600c2727b8f8538f84fa456f783edd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_uuid_utoken_pid", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getTBOAuth2Url(Integer ctype,Integer rtype, String pid, String uuid, String utoken, String token) {
		if (StringUtils.isBlank(pid)) {
			return new RSPE<String>(-2, "pid不能为空！");
		}
		if (StringUtils.isBlank(uuid)) {
			return new RSPE<String>(-3, "随机数不能为空！");
		}
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<String>(-4, "系统平台参数错误！");
		}
//		if (ctype == null || (ctype != 0 && ctype != 1)) {
//			return new RSPE<String>(-4, "应用平台参数错误！");
//		}
		/* 查看是否存在 */
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
		if (zdev == null) {
			return new RSPE<String>(-5, "用户不存在，请注册后重试！");
		} else if (StringUtils.isNotBlank(zdev.getTbrid())) {
			return new RSPE<String>(-6, "此用户已经绑定，请勿重复操作！");
		}
		Callable<RSPE<String>> result = new Callable<RSPE<String>>() {
			@Override
			public RSPE<String> call() throws Exception {
				return new RSPE<String>(catDevService.getTbOAuth2Url(ctype,rtype, zdev, pid));
			}
		};
		return result;
	}

	@PostMapping("/get/signed/info")
	@ApiOperation(value = "9趣猫用户获取签到信息", position = 8, notes = "个人中心点击右上角金币，请求签到数据", consumes = "application/x-www-form-urlencoded", response = CatDevSignedHistoryResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "5380881829", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "version", value = "版本号", example = "102", required = false, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_utoken_pid_time)", example = "600c2727b8f8538f84fa456f783edd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_uuid_utoken_pid", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getSignedInfo(Integer rtype, String pid,
			@RequestParam(required = false, defaultValue = "102") String version, String uuid, String utoken,
			String token, HttpServletRequest request) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		Callable<RSPE<CatDevSignedHistoryResp>> result = new Callable<RSPE<CatDevSignedHistoryResp>>() {
			@Override
			public RSPE<CatDevSignedHistoryResp> call() throws Exception {
				return new RSPE<CatDevSignedHistoryResp>(catDevService.getSignedInfo(rtype, pid, version));
			}
		};
		return result;
	}

	@PostMapping("/signed/double")
	@ApiOperation(value = "9趣猫用户获取签到现金豆翻倍接口", notes = "9趣猫用户获取签到现金豆翻倍接口！", consumes = "application/x-www-form-urlencoded", position = 9, response = RSPE.class, responseContainer = "Map")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户PID", example = "5371329791", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "fid", value = "中奖翻倍ID", example = "5371329791", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_fid_utoken_pid_pid_rtype_uuid_time)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form") })

	@CheckingMD5(checkingStr = "uuid_fid_utoken_pid_pid_rtype_uuid", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getTurnDrawDouble(Integer rtype, String pid, String fid, String utoken, String uuid, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		CatDevSignedBeansHistory beansHistory = signedBeansHistoryRepository.findByPidAndFid(pid, fid);
		if (beansHistory == null) {
			return new RSPE<Object>(-3, "抽奖信息不存在！");
		}
		if (beansHistory.getFstatus() == -1) {
			return new RSPE<Object>(-4, "此奖励不支持翻倍！");
		}
		if (beansHistory.getFstatus() == 1) {
			return new RSPE<Object>(-5, "已经翻倍，请不要重复请求！");
		}
		Callable<RSPE<Map<String, Object>>> result = new Callable<RSPE<Map<String, Object>>>() {
			@Override
			public RSPE<Map<String, Object>> call() throws Exception {
				Map<String, Object> infoDouble = catDevService.getSignedInfoDouble(beansHistory);
				if (infoDouble == null) {
					return new RSPE<Map<String, Object>>(0, "翻倍失败！");
				}
				return new RSPE<Map<String, Object>>(infoDouble);
			}
		};
		return result;
	}

	@PostMapping("/signed/daily")
	@ApiOperation(value = "9趣猫用户进行每日签到", notes = "用户每日首次，看完视频后，进行签到领取现金豆！", consumes = "application/x-www-form-urlencoded", position = 9, response = CatDevSignedHistoryResp.class, responseContainer = "Map")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户PID", example = "5371329791", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_utoken_pid_pid_rtype_uuid_time)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form") })

	@CheckingMD5(checkingStr = "uuid_utoken_pid_pid_rtype_uuid", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getSignedDaily(Integer rtype, String pid, String utoken, String uuid, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		/* 查询今日是否已签到成功 */
		CatDevSignedHistoryResp historyResp = signedHistoryRespDao.selectOne(new CatDevSignedHistory(pid),
				"get7SignInNumberDays");
		if (historyResp.getEndDate().equals(LocalDate.now().toString()) && historyResp.getSigns() != 0) {
			return new RSPE<Object>(-3, "今日已签到！");
		}
		Callable<RSPE<CatDevSignedHistoryResp>> result = new Callable<RSPE<CatDevSignedHistoryResp>>() {
			@Override
			public RSPE<CatDevSignedHistoryResp> call() throws Exception {
				CatDevSignedHistoryResp resp = catDevService.setSignedDaily(pid);
				if (resp == null) {
					return new RSPE<CatDevSignedHistoryResp>(0, "签到失败！");
				}
				return new RSPE<CatDevSignedHistoryResp>(resp);
			}
		};
		return result;
	}

	@PostMapping("/get/bonus/info")
	@ApiOperation(value = "9趣猫用户现金红包信息", position = 10, notes = "现金红包列表信息", consumes = "application/x-www-form-urlencoded", response = CatCashBonusHistoryResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "5380881829", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_utoken_pid_time)", example = "600c2727b8f8538f84fa456f783edd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_uuid_utoken_pid", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getCashBonusInfo(Integer rtype, String pid, String uuid, String utoken, String token, Pages pages) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		Callable<RSPE<CatCashBonusHistoryResp>> result = new Callable<RSPE<CatCashBonusHistoryResp>>() {
			@Override
			public RSPE<CatCashBonusHistoryResp> call() throws Exception {
				return new RSPE<CatCashBonusHistoryResp>(catDevService.getCashBonusInfo(rtype, pid, pages));
			}
		};
		return result;
	}

	@PostMapping("/upd/alipay")
	@ApiOperation(value = "9趣猫用户修改支付宝绑定信息", consumes = "application/x-www-form-urlencoded", position = 11, notes = "", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "UID_39D970F3F2DFE55FE6BAC85B79633B24", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "account", value = "支付宝账号", example = "11111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "realname", value = "支付宝账户真实姓名", example = "张三", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_account_uuid_utoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_account_uuid_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object updAlipay(Integer rtype, String pid, String account, String realname, String uuid, String utoken,
			String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		if (StringUtils.isBlank(account) || StringUtils.isBlank(realname)) {
			return new RSPE<Boolean>(-3, "更改信息格式错误！");
		}
		if (!realname.matches("^([\\u4e00-\\u9fa5]{1,20}|[a-zA-Z\\.\\s]{1,20})$")) {
			return new RSPE<Boolean>(-4, "真实姓名格式错误,请正确填写！");
		}
		// 判断支付宝账号是否已经被绑定
		CatDevUserInfo devUserInfo = userInfoRepository.findByZaccount(account);
		if (devUserInfo != null && !devUserInfo.getPid().equals(pid)) {
			return new RSPE<Boolean>(-5, "此支付宝账号已被绑定！");
		}
		/* 查看是否存在 */
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
		if (zdev == null) {
			return new RSPE<Boolean>(-4, "用户信息不存在错误！");
		}
		Callable<RSPE<Boolean>> result = new Callable<RSPE<Boolean>>() {
			@Override
			public RSPE<Boolean> call() throws Exception {
				Boolean isSuccess = catDevService.updAlipay(rtype, zdev, pid, account, realname);
				if (isSuccess != null && isSuccess) {
					return new RSPE<Boolean>(1, "修改成功！");
				} else {
					return new RSPE<Boolean>(-1, "修改失败！");
				}
			}
		};
		return result;
	}

	@PostMapping("/get/rincome")
	@ApiOperation(value = "9趣猫用户领取注册奖励", consumes = "application/x-www-form-urlencoded", position = 12, notes = "注册后，弹窗领取现金、金豆奖励,点击确认后领取", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "UID_39D970F3F2DFE55FE6BAC85B79633B24", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "jtype", value = "奖励类型（0.现金豆、1.现金 、2.肥料）", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_jtype_uuid_utoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_jtype_uuid_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getRegisterIncome(Integer rtype, Integer jtype, String pid, String uuid, String utoken,
			String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		if (jtype == null || (jtype != 0 && jtype != 1 && jtype !=2)) {
			return new RSPE<Boolean>(-3, "奖励类型错误！");
		}
		CatDevRegisterIncomeHistory zdev = catDevRegisterIncomeHistoryRepository.findByPidAndRtype(pid, jtype);
		if (zdev == null) {
			return new RSPE<Boolean>(-4, "奖励信息不存在！");
		}
		if (zdev.getLstatus() == 1) {
			return new RSPE<Boolean>(-5, "奖励已领取！");
		}

		Callable<RSPE<Boolean>> result = new Callable<RSPE<Boolean>>() {
			@Override
			public RSPE<Boolean> call() throws Exception {
				if (catDevService.getRegisterIncome(rtype, pid, zdev)) {
					return new RSPE<Boolean>(1, "修改成功！");
				}
				return new RSPE<Boolean>(-1, "修改失败！");
			}
		};
		return result;
	}

	@PostMapping("/authentication")
	@ApiOperation(value = "9趣猫用户实名认证", consumes = "application/x-www-form-urlencoded", position = 13, notes = "", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "5516603495", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "realname", value = "真实姓名", example = "张三", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "idcard", value = "身份证号", example = "", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "purl", value = "身份证正面地址", example = "http://", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "burl", value = "身份证背面地址", example = "http://", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_realname_burl_idcard_uuid_utoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_realname_burl_idcard_uuid_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object authentication(Integer rtype, String pid, String realname, String idcard, String purl, String burl,
			String uuid, String utoken, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		if (StringUtils.isBlank(realname) || StringUtils.isBlank(idcard)) {
			return new RSPE<Boolean>(-4, "身份证号与真实姓名不能为空！");
		}
		if (StringUtils.isBlank(purl) || StringUtils.isBlank(burl)) {
			return new RSPE<Boolean>(-3, "认证图片为空错误！");
		}
		/* 查看是否存在 */
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
		if (zdev == null) {
			return new RSPE<Boolean>(-4, "用户信息不存在错误！");
		}
		Callable<RSPE<Boolean>> result = new Callable<RSPE<Boolean>>() {
			@Override
			public RSPE<Boolean> call() throws Exception {
				if (catDevService.authentication(rtype, zdev, realname, idcard, purl, burl)) {
					return new RSPE<Boolean>(1, "提交成功！");
				}
				return new RSPE<Boolean>(-1, "提交失败！");
			}
		};
		return result;
	}

	@PostMapping("/beans/video")
	@ApiOperation(value = "9趣猫看视频领取金豆", consumes = "application/x-www-form-urlencoded", position = 14, notes = "看视频领取金豆", response = CatDevBeanVideoHistoryResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "5516603495", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "ltype", value = "来源类型(0.福利中心(默认)、1.首页弹窗、2.刮刮卡弹窗、3.神奇便利店)", example = "0", required = false, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_pid_utoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_uuid_pid_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getBeansByVideo(Integer rtype, String pid,
			@RequestParam(required = false, defaultValue = "0") Integer ltype, String uuid, String utoken,
			String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		if (ltype == null || (ltype < 0 || ltype > 3)) {
			return new RSPE<Boolean>(-3, "奖励来源类型不存在！");
		}
		/* 查看是否存在 */
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
		if (zdev == null) {
			return new RSPE<Boolean>(-4, "用户信息不存在错误！");
		}
		CatDevBeanVideoHistoryResp videoHistoryResp = cacheService.getBeanVideoHistory(pid, ltype);
		// 如果来源为福利中心,则判断是否满足条件
		if (ltype == 0) {
			// 获取今日观看视频次数及最后一次领取的时间
			if (videoHistoryResp.getDcount() >= 3) {
				return new RSPE<Boolean>(-5, "今日次数已用完！");
			}
			// 判断时间是否可领取
			if (videoHistoryResp.getEndTime() != null) {
				LocalDateTime nextTime = LocalDateTime
						.parse(videoHistoryResp.getEndTime(), DateAPIUtils.FORMATTER_YYYYMMDDHHMMSS).plusMinutes(5);
				if (nextTime.isAfter(LocalDateTime.now())) {
					return new RSPE<Boolean>(-6, "未到下次领取时间！");
				}
			}
		} else {
			// 如果今日已领取，则返回今日已领取
			if (videoHistoryResp.getDcount() >= 1) {
				return new RSPE<Boolean>(-5, "今日领取次数已用完！");
			}
		}
		/* 查看用户今日已领取次数 */
		Callable<RSPE<CatDevBeanVideoHistoryResp>> result = new Callable<RSPE<CatDevBeanVideoHistoryResp>>() {
			@Override
			public RSPE<CatDevBeanVideoHistoryResp> call() throws Exception {
				CatDevBeanVideoHistoryResp resp = catDevService.getBeansByVideo(rtype, pid, ltype);
				if (resp != null) {
					return new RSPE<CatDevBeanVideoHistoryResp>("领取成功", resp);
				}
				return new RSPE<CatDevBeanVideoHistoryResp>(-1, "领取失败！");
			}
		};
		return result;
	}

	@PostMapping("/welfare")
	@ApiOperation(value = "9趣猫获取数据福利中心", consumes = "application/x-www-form-urlencoded", position = 15, notes = "获取数据福利中心", response = CatDevWelfareInfoResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "5516603495", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_pid_utoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_uuid_pid_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getWelfareInfo(Integer rtype, String pid, String uuid, String utoken, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		/* 查看是否存在 */
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
		if (zdev == null) {
			return new RSPE<Boolean>(-4, "用户信息不存在错误！");
		}

		/* 查看用户今日已领取次数 */
		Callable<RSPE<CatDevWelfareInfoResp>> result = new Callable<RSPE<CatDevWelfareInfoResp>>() {
			@Override
			public RSPE<CatDevWelfareInfoResp> call() throws Exception {
				CatDevWelfareInfoResp resp = catDevService.getWelfareInfo(rtype, pid);
				if (resp != null) {
					return new RSPE<CatDevWelfareInfoResp>(resp);
				}
				return new RSPE<CatDevWelfareInfoResp>(-1, "获取失败！");
			}
		};
		return result;
	}

    /**
     * 根据用户pid查询用户福利中心信息
     * @param rtype
     * @param pid
     * @param uuid
     * @param utoken
     * @param token
     * @return
     */
    @PostMapping("/welfareCentr")
    @ApiOperation(value = "获取用户福利中心数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pid", value = "登录返回字段", example = "5516603495", dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "token", value = "MD5(pid_uuid_pid_utoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
    @CheckingMD5(checkingStr = "pid_uuid_pid_utoken", MD5 = "token", checkSingle = true)
    @CheckDevPermission
    public RSPE<Object> getCatUserWelfareCentrByPid(Integer rtype, String pid, String uuid,
                                                    String utoken, String token) {
        if (rtype == null || (rtype != 0 && rtype != 1)) {
            return new RSPE<Object>(-2, "应用平台参数错误！");
        }
        /* 查看是否存在 */
        CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
        if (zdev == null) {
            return new RSPE<Object>(-4, "用户信息不存在错误！");
        }
        CatUserWelfareCentr userWelfareCentr = catUserWelfareCentrService.getCatUserWelfareCentrByPid(pid);
        //判断用户福利中心是否为空，
        if(userWelfareCentr == null){
            //空代表用户首次打开福利中心页面,先帮用户注册福利中心，新增用户信息，到福利中心表
			int i = catUserWelfareCentrService.addCatUserWelfareCentrByPid(CatUserWelfareCentr.builder().pid(pid).build());
			if(i != 1){  //是否注册成功
				return new RSPE<Object>(0, "注册福利中心失败");
			}
			//注册成功后再次查询用户福利中心
			userWelfareCentr = catUserWelfareCentrService.getCatUserWelfareCentrByPid(pid);
		}
        return new RSPE<Object>(1, "success",userWelfareCentr);
    }



    @PostMapping("/updateCatUserWelfareCentrByPid")
    @ApiOperation(value = "修改用户福利中心数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "pid", value = "登录返回字段", example = "5516603495", dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "token", value = "MD5(pid_uuid_pid_utoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "gold", value = "用户金币总额", example = "1000",required = true, dataType = "Integer", paramType = "form"),
            @ApiImplicitParam(name = "signinRemind", value = "签到提醒 （0表示关，1表示开，默认 0）", example = "0",required = true, dataType = "Integer", paramType = "form"),
            @ApiImplicitParam(name = "todaySigninStatus", value = "（用户今日是否签到：0表示未签到，1表示已签到）", example = "0",required = true, dataType = "Integer", paramType = "form"),
            @ApiImplicitParam(name = "signinSum", value = "用户连续签到天数总和", example = "7",required = true, dataType = "Integer", paramType = "form"),
            @ApiImplicitParam(name = "todayGold", value = "用户今日获得金币总和", example = "1000",required = true, dataType = "Integer", paramType = "form"),
			@ApiImplicitParam(name = "intoBookrack", value = "用户今日是否进入书架 (0:未完成,1：已完成)", example = "0",required = true, dataType = "Integer", paramType = "form"),
			@ApiImplicitParam(name = "todayRead", value = "用户每日阅读 (0:未完成,1：已完成)", example = "0",required = true, dataType = "Integer", paramType = "form"),
			@ApiImplicitParam(name = "inviter", value = "邀请好友 （每天可邀请2次 0,1,2）", example = "0",required = true, dataType = "Integer", paramType = "form"),
			@ApiImplicitParam(name = "video", value = "看视频(每天可看 10次)", example = "0",required = true, dataType = "Integer", paramType = "form"),
			@ApiImplicitParam(name = "readTen", value = "阅读10分钟(0:未完成,1：已完成)", example = "0",required = true, dataType = "Integer", paramType = "form"),
			@ApiImplicitParam(name = "readThirty", value = "阅读30分钟(0:未完成,1：已完成)", example = "0",required = true, dataType = "Integer", paramType = "form"),
			@ApiImplicitParam(name = "readSixty", value = "阅读60分钟(0:未完成,1：已完成)", example = "0",required = true, dataType = "Integer", paramType = "form"),
			@ApiImplicitParam(name = "readOneTwoZero", value = "阅读120分钟(0:未完成,1：已完成)", example = "0",required = true, dataType = "Integer", paramType = "form"),
			@ApiImplicitParam(name = "readOneEightZero", value = "阅读180分钟(0:未完成,1：已完成)", example = "0",required = true, dataType = "Integer", paramType = "form"),
			@ApiImplicitParam(name = "cz", value = "执行什么操作",
					example = "1签到提醒，2今日签到，3金币兑换免视频时长,4.进入书架，" +
							"5每日阅读,6邀请好友，7看视频领金币，8，阅读10分钟，9，阅读30分钟，10阅读60分钟，" +
							"11阅读120分钟，12阅读180分钟",
					required = true, dataType = "Integer", paramType = "form")})
    @CheckingMD5(checkingStr = "pid_uuid_pid_utoken", MD5 = "token", checkSingle = true)
    @CheckDevPermission
    public RSPE<Object> updateCatUserWelfareCentrByPid(Integer rtype, String pid,Integer gold,
                                                       Integer signinRemind,Integer todaySigninStatus,
                                                       Integer signinSum,Integer todayGold,
													   Integer intoBookrack,Integer todayRead,
													   Integer inviter,Integer video,
													   Integer readTen,Integer readThirty,
													   Integer readSixty,Integer readOneTwoZero,
													   Integer readOneEightZero,String uuid,
                                                    String utoken, String token,Integer cz) {
		System.out.println("pid:"+pid);
		System.out.println("gold:"+gold);
		System.out.println("signinRemind:"+signinRemind);
		System.out.println("todaySigninStatus:"+todaySigninStatus);
		System.out.println("signinSum:"+signinSum);
		System.out.println("todayGold:"+todayGold);
		System.out.println("cz:"+cz);
        if (rtype == null || (rtype != 0 && rtype != 1)) {
            return new RSPE<Object>(-2, "应用平台参数错误！");
        }
        /* 查看是否存在 */
        CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
        if (zdev == null) {
            return new RSPE<Object>(-4, "用户信息不存在错误！");
        }
        if(cz == null){  //操作
            return new RSPE<Object>(-7, "缺少参数cz");
        }
        CatUserWelfareCentr userWelfareCentr = catUserWelfareCentrService.getCatUserWelfareCentrByPid(pid);
        //判断用户福利中心是否为空，
        if(userWelfareCentr == null){
            return new RSPE<Object>(-5, "用户还没有注册福利中心！");
        }
        if(cz == 2){ //今日签到操作
			if(userWelfareCentr.getTodaySigninStatus() == 1){
				return new RSPE<Object>(-8, "今日已签到，请勿重复签到");
			}
			signinSum = userWelfareCentr.getSigninSum()+1;  //用户连续签到天数总和 +1
			if(signinSum == 1 || signinSum == 2 ||
					signinSum == 4 || signinSum == 5 || signinSum == 6){
				//连续签到 1.2。4.5.6 天 加 100金币
				gold = userWelfareCentr.getGold() + 100; //金币总额
				todayGold = userWelfareCentr.getTodayGold() + 100; //今日共得金币
			}else if(signinSum == 3){
				//连续签到 3 天 加 300金币
				gold = userWelfareCentr.getGold() + 300;//金币总额
				todayGold = userWelfareCentr.getTodayGold() + 300;//今日共得金币
			}else if(signinSum == 7){
				//免费vip1小时
			}
		}else if(cz == 3){  //金币兑换免视频时长
            //消耗300金币兑换免广告时长180分钟
            //判断用户金币是否足够
            if(userWelfareCentr.getGold() < 300){
                return new RSPE<Object>(-9, "兑换失败，金币不足300");
            }
            //金币足够 减300金币
            gold = userWelfareCentr.getGold() - 300;
        }else if(cz == 4){  //进入书架
        	//判断用户今日是否已进入过书架
			if(userWelfareCentr.getIntoBookrack() == 1){
				return new RSPE<Object>(-10, "已领取过该奖励，请勿重复领取");
			}
			intoBookrack = 1; //进入书架
			gold = userWelfareCentr.getGold() + 100;//每日首次进入书架加100金币
			todayGold = userWelfareCentr.getTodayGold() + 100; //今日共得金币
		}else if(cz == 5){  //5每日阅读
			if(userWelfareCentr.getTodayRead() == 1){
				return new RSPE<Object>(-11, "已领取过该奖励，请勿重复领取");
			}
			todayRead = 1; //每日阅读
			gold = userWelfareCentr.getGold() + 100;//每日阅读加100金币
			todayGold = userWelfareCentr.getTodayGold() + 100; //今日共得金币
		}else if(cz == 6){ //6邀请好友
			if(userWelfareCentr.getInviter() >= 2){
				return new RSPE<Object>(-12, "邀请好友奖励每日只可领取两次");
			}
			inviter = userWelfareCentr.getInviter()+1;
			gold = userWelfareCentr.getGold() + 100;//每日邀请一次好友加100金币,最多两次
			todayGold = userWelfareCentr.getTodayGold() + 100; //今日共得金币
		}else if(cz == 7){ //7看视频领金币
			if(userWelfareCentr.getVideo() >= 10){
				return new RSPE<Object>(-13, "看视频领金币,每日只可领取10次");
			}
			video = userWelfareCentr.getVideo() + 1;
			gold = userWelfareCentr.getGold() + 200;
			todayGold = userWelfareCentr.getTodayGold() + 200; //今日共得金币
		}else if(cz == 8){//8，阅读10分钟
			if(userWelfareCentr.getReadTen() == 1){
				return new RSPE<Object>(-14, "已领取过该奖励，请勿重复领取");
			}
			readTen = 1;
			gold = userWelfareCentr.getGold() + 30; //阅读十分钟加30
			todayGold = userWelfareCentr.getTodayGold() + 30; //今日共得金币
		}else if(cz == 9){//9，阅读30分钟
			if(userWelfareCentr.getReadThirty() == 1){
				return new RSPE<Object>(-15, "已领取过该奖励，请勿重复领取");
			}
			readThirty = 1;
			gold = userWelfareCentr.getGold() + 80; //阅读30分钟加80
			todayGold = userWelfareCentr.getTodayGold() + 80; //今日共得金币
		}else if(cz == 10){//10阅读60分钟
			if(userWelfareCentr.getReadSixty() == 1){
				return new RSPE<Object>(-16, "已领取过该奖励，请勿重复领取");
			}
			readSixty = 1;
			gold = userWelfareCentr.getGold() + 90; //阅读60分钟加90
			todayGold = userWelfareCentr.getTodayGold() + 90; //今日共得金币
		}else if(cz == 11){//11阅读120分钟
			if(userWelfareCentr.getReadOneTwoZero() == 1){
				return new RSPE<Object>(-17, "已领取过该奖励，请勿重复领取");
			}
			readOneTwoZero = 1;
			gold = userWelfareCentr.getGold() + 100; //阅读120分钟加100
			todayGold = userWelfareCentr.getTodayGold() + 100; //今日共得金币
		}else if(cz == 12){//12阅读180分钟
			if(userWelfareCentr.getReadOneEightZero() == 1){
				return new RSPE<Object>(-18, "已领取过该奖励，请勿重复领取");
			}
			readOneEightZero = 1;
			gold = userWelfareCentr.getGold() + 150; //阅读180分钟加150
			todayGold = userWelfareCentr.getTodayGold() + 150; //今日共得金币
		}
        //更新用户福利中心数据
		Map<String,Object> map = new HashMap<>();
		map.put("pid",pid);
		map.put("gold",gold);
		map.put("signinRemind",signinRemind);
		map.put("todaySigninStatus",todaySigninStatus);
		map.put("signinSum",signinSum);
		map.put("todayGold",todayGold);
		map.put("intoBookrack",intoBookrack);
		map.put("todayRead",todayRead);
		map.put("inviter",inviter);
		map.put("video",video);
		map.put("readTen",readTen);
		map.put("readThirty",readThirty);
		map.put("readSixty",readSixty);
		map.put("readOneTwoZero",readOneTwoZero);
		map.put("readOneEightZero",readOneEightZero);
        int i = catUserWelfareCentrService.updateCatUserWelfareCentrByPid(map);
        if(i == 0){
            return new RSPE<Object>(-6, "操作失败");
        }
        return new RSPE<Object>(1, "success",null);
    }

	@PostMapping("/remit/info")
	@ApiOperation(value = "9趣猫获取提现信息", consumes = "application/x-www-form-urlencoded", position = 16, notes = "9趣猫获取提现信息", response = CatDevRemitInfoResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "5516603495", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_pid_uuid_pid_utoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "rtype_pid_uuid_pid_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getRemitInfo(Integer rtype, String pid, String uuid, String utoken, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		/* 查看是否存在 */
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
		if (zdev == null) {
			return new RSPE<Boolean>(-4, "用户信息不存在错误！");
		}

		/* 查看用户今日已领取次数 */
		Callable<RSPE<CatDevRemitInfoResp>> result = new Callable<RSPE<CatDevRemitInfoResp>>() {
			@Override
			public RSPE<CatDevRemitInfoResp> call() throws Exception {
				CatDevRemitInfoResp resp = catDevService.getRemitInfo(rtype, pid);
				if (resp != null) {
					return new RSPE<CatDevRemitInfoResp>(resp);
				}
				return new RSPE<CatDevRemitInfoResp>(-1, "获取失败！");
			}
		};
		return result;
	}

	@PostMapping("/wechat/isfocus")
	@ApiOperation(value = "9趣猫获取用户是否已关注微信公众号", consumes = "application/x-www-form-urlencoded", position = 17, notes = "9趣猫获取用户是否已关注微信公众号", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "5516603495", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_pid_uuid_pid_utoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "rtype_pid_uuid_pid_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getIsFocusWeChat(Integer rtype, String pid, String uuid, String utoken, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		/* 查看是否存在 */
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
		if (zdev == null) {
			return new RSPE<Boolean>(-4, "用户信息不存在错误！");
		}

		/* 查看用户今日已领取次数 */
		Callable<RSPE<Integer>> result = new Callable<RSPE<Integer>>() {
			@Override
			public RSPE<Integer> call() throws Exception {
				Integer IsFocusWeChat = catDevService.getIsFocusWeChat(rtype, pid, zdev.getUnionid());
				if (IsFocusWeChat != null) {
					return new RSPE<Integer>(IsFocusWeChat);
				}
				return new RSPE<Integer>(-1, "获取失败！");
			}
		};
		return result;
	}

	@PostMapping("/remit/wechat")
	@ApiOperation(value = "9趣猫微信公众号获取提现历史记录", position = 18, notes = "9趣猫微信公众号获取提现历史记录", consumes = "application/x-www-form-urlencoded", response = CatDevRemitRecordResp.class, responseContainer = "List")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "code", value = "微信code", example = "5380881829", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "mode", value = "提现方式（0.正常提款、1.正常邀请提现、2.互拆邀请提现、10.全部）", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_code_mode_code_time)", example = "1001", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_code_mode_code", MD5 = "token")
	public Object remitWeChatList(Integer mode, String code, String uuid, String token, Pages pages) {
		if (mode == null || Arrays.binarySearch(new int[] { 0, 1, 2, 3, 10 }, mode) < 0) {
			return new RSPE<Object>(-3, "提现方式参数错误！");
		}

		Callable<RSPE<ResultPage<CatDevRemitRecordResp>>> result = new Callable<RSPE<ResultPage<CatDevRemitRecordResp>>>() {
			@Override
			public RSPE<ResultPage<CatDevRemitRecordResp>> call() throws Exception {
				ResultPage<CatDevRemitRecordResp> resultPage = catDevService.remitWeChatList(code, pages, mode);
//				if (resultPage!=null) {
				return new RSPE<ResultPage<CatDevRemitRecordResp>>(resultPage);
//				}else {
//					return new RSPE<ResultPage<CatDevRemitRecordResp>>(0,"获取失败");
//				}
			}
		};
		return result;
	}

	@PostMapping("/account/login")
	@ApiOperation(value = "9趣猫账号密码登录", position = 19, notes = "测试审核使用", consumes = "application/x-www-form-urlencoded", response = CatDevUserInfoResp.class, responseContainer = "List")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "account", value = "账号", example = "5380881829", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "password", value = "密码(MD5加密)", example = "5380881829", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(account_uuid_password_rtype_time)", example = "1001", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "account_uuid_password_rtype", MD5 = "token", checkSingle = true, singleStr = "account")
	public Object accountLogin(Integer rtype, String account, String password, String uuid, String token,
			HttpServletRequest request) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		if (StringUtils.isBlank(account)) {
			return new RSPE<CatDevUserInfoResp>(-3, "登录账号不能为空！");
		}
		if (StringUtils.isBlank(password)) {
			return new RSPE<CatDevUserInfoResp>(-5, "登录密码不能为空！");
		}
		// 判断密码是否正确
		if (!"0aa652b1089be70b23d03b738862e1e6".equals(password)) {
			return new RSPE<CatDevUserInfoResp>(-4, "登录密码错误");
		}
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(account);
		if (zdev == null) {
			return new RSPE<Boolean>(-4, "用户信息不存在错误！");
		}

		Callable<RSPE<CatDevUserInfoResp>> result = new Callable<RSPE<CatDevUserInfoResp>>() {
			@Override
			public RSPE<CatDevUserInfoResp> call() throws Exception {
				CatDevUserInfoResp respDev = catDevService.accountLogin(rtype, account, request);
				if (respDev == null) {
					return new RSPE<CatDevUserInfoResp>(-10, "用户登录失败！");
				}
				return new RSPE<CatDevUserInfoResp>(respDev);
			}
		};
		return result;
	}

	@PostMapping("/account/logout")
	@ApiOperation(value = "9趣猫用户注销", position = 20, notes = "9趣猫用户注销", consumes = "application/x-www-form-urlencoded", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "5516603495", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_pid_utoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_uuid_pid_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object accountLogout(Integer rtype, String pid, String uuid, String utoken, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Boolean>(-2, "应用平台参数错误！");
		}
		/* 查看是否存在 */
		CatDevUserInfo zdev = catDevService.getCatDevUserInfoByPid(pid);
		if (zdev == null) {
			return new RSPE<Boolean>(-3, "用户信息不存在错误！");
		}
		Pages pages = new Pages(1, 10);
		// 检测是否有正在进行中的订单
		ResultPage<CatDevOrderResp> resultPage = catDevOrderRespDao.listAndPages(new CatDevOrderResp(pid, 0,10),
				"getOrderList", pages);
		if (resultPage != null && resultPage.getList() != null && resultPage.getList().size() > 0) {
			return new RSPE<Boolean>(-4, "您有未完成的订单,暂无法注销！");
		}
		// 判断是否含有正在提现的记录
		if (intDao.selectOne(new CatDevRemitRecordResp(pid), "selectUnfinishedCount") > 0) {
			return new RSPE<Boolean>(-5, "您有审核中或提现中的提现记录,暂无法注销！");
		}
		// 判断拆红包是否有未结束或已达标但未提现的记录
		CatDevHCInviteInfoResp inviteInfoResp = hcInviteInfoRespDao.selectOne(new CatDevHCInviteInfoResp(pid),
				"getInviteNewUserRimit");
		// 判断本轮是否达标,如果已达标则判断是否提现
		if (inviteInfoResp != null) {
			if (hcInviteInfoRespDao.selectOne(new CatDevHCInviteInfoResp(pid), "getInviteNewUserRimit") == null) {
				return new RSPE<Boolean>(-6, "注销失败,拆红包活动含未提现红包！");
			}
		}
		// 判断直接邀请是否含未体现红包
		if (cacheService.getInviteNewUserIncome(pid) > 0) {
			return new RSPE<Boolean>(-7, "注销失败,邀请好友活动含未提现红包！");
		}

		// 获取已注册账号的数量,每人最多只能注销四次,第五次注销提示注销数量过多无法再注销
		List<CatDevUserInfo> list = userInfoRepository.findByUnionid(zdev.getUnionid());
		if (list != null && list.size() >= 5) {
			return new RSPE<Boolean>(-8, "注销失败,设备注销账号过多！");
		}
		Callable<RSPE<Boolean>> result = new Callable<RSPE<Boolean>>() {
			@Override
			public RSPE<Boolean> call() throws Exception {
				if (catDevService.accountLogout(pid, zdev)) {
					return new RSPE<Boolean>(1, "注销成功！", true);
				}
				return new RSPE<Boolean>(-1, "注销失败！");
			}
		};
		return result;
	}
 
	@PostMapping("/taotaoji/login")
	@ApiOperation(value = "用户微信登录/注册", position = 1, consumes = "application/x-www-form-urlencoded", notes = "个人信息(基本信息+收入信息)", response = CatDevUserInfoResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pindex", value = "页面请求位置 (0. 首页、1.我的个人中心)", example = "0", required = false, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "brand", value = "手机品牌", example = "Honer", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "model", value = "品牌型号", example = "HSF-001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "APP友盟渠道ID", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
//			@ApiImplicitParam(name = "nikename", value = "微信昵称", example = "春暖錵疏🚗", required = true, dataType = "String", paramType = "form"),
//			@ApiImplicitParam(name = "pid", value = "邀请人的PID(无为自注册)", example = "C85B79633B24", dataType = "String", paramType = "form"),
//			@ApiImplicitParam(name = "sex", value = "性别(0.女、1.男)", example = "1", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "code", value = "微信登录CODE", example = "UID_39D970F3F2DFE55FE6BAC85B79633B24", required = true, dataType = "String", paramType = "form"),
//			@ApiImplicitParam(name = "icon", value = "微信头像", example = "https://", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(code_uuid_rtype_code_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "code_uuid_rtype_code", MD5 = "token")
	public Object pinDuoLogin(Integer rtype,@RequestParam(required = false,defaultValue = "-1") Integer pindex, String brand, String model, String vscode, String cid, String imei, String imsi,
			String code, String uuid, String token) {
		return login("", rtype, 1, pindex, brand, model, vscode, cid, imei, imsi, code, uuid, token);
	}
	
	@PostMapping("/get/task/reward")
	@ApiOperation(value = "9趣猫用户获取任务奖励", consumes = "application/x-www-form-urlencoded", position = 4, notes = "9趣猫用户获取任务奖励", response = UserTaskData.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "登录返回字段", example = "UID_39D970F3F2DFE55FE6BAC85B79633B24", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "taskType", value = "任务类型(0.复制标题、1.绑定手机号、2.首次下单、3.新用户一元提现)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "登录返回字段", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(pid_uuid_taskType_utoken_pid_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "pid_uuid_taskType_utoken_pid", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getTaskReward(Integer rtype, Integer taskType, String pid, String uuid, String utoken,
			String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<UserTaskData>(-2, "应用平台参数错误！");
		}
		if (taskType==null || taskType<0) {
			return new RSPE<UserTaskData>(-3, "任务类型不存在！");
		}
		//判断任务类型是否存在
		if(catDevUserTaskConfigRepository.findByTypeId(taskType)==null) {
			return new RSPE<UserTaskData>(-3, "任务类型不存在！");
		}
		
		//判断任务是否已完成
		CatDevUserTaskRecord taskRecord = newUserTaskRecordRepository.queryByPidAndTaskTypeOrderByTaskType(pid, taskType);
		//如果为复制商品标题,除新用户复制商品奖励外还有每日3次复制商品标题奖励
		if (taskType==0 && (taskRecord==null || taskRecord.getReceiveStatus()==1)) {
			taskRecord = newUserTaskRecordRepository.queryByPidAndTaskTypeOrderByTaskType(pid, 5);
		}
		if (taskRecord==null) {
			return new RSPE<UserTaskData>(-4, "任务奖励不存在！");
		}
		if (taskRecord.getReceiveStatus()==1) {
			return new RSPE<UserTaskData>(-5, "任务奖励已领取！");
		}
		
		//判断任务是否完成
		if (taskRecord.getTaskType()==2) {
			//判断用户是否已经有订单记录
			Integer number = cacheService.getOrderNumber(taskRecord.getPid(),taskRecord.getPid(),null);
			if (number==null || number==0) {
				return new RSPE<UserTaskData>(-6, "任务未完成！");
			}
		}else if (taskRecord.getTaskType()==8) {
			//每日首单奖励
			//判断用户是否已经有订单记录
			Integer number = cacheService.getOrderNumber(taskRecord.getPid()+LocalDate.now().toString(),taskRecord.getPid(),LocalDate.now().toString());
			if(number == null || number == 0) {
				return new RSPE<UserTaskData>(-6, "任务未完成！");
			}
		}
		CatDevUserTaskRecord task=taskRecord;
		Callable<RSPE<UserTaskData>> result = new Callable<RSPE<UserTaskData>>() {
			@Override
			public RSPE<UserTaskData> call() throws Exception {
				UserTaskData data = catDevService.getTaskReward(rtype, task);
				if (data != null) {
					return new RSPE<UserTaskData>(data);
				}
				return new RSPE<UserTaskData>(0, "领取失败！");
			}
		};
		return result;
	}
	
	@PostMapping("/commit/feedback")
	@ApiOperation(value = "提交使用反馈", position = 8, consumes = "application/x-www-form-urlencoded", notes = "9趣猫app使用反馈", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "brand", value = "手机品牌", example = "Honer", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "model", value = "品牌型号", example = "HSF-001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "type", value = "反馈类型(1.商品购买、2.邀请问题...)", example = "1", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "questionDesc", value = "反馈问题描述", example = "", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "questionPic", value = "反馈问题图片地址", example = "", required = false, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "appId", value = "应用ID(0.九趣猫(默认)、1.淘淘集、2.一陶)", example = "0", required = false, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_brand_imei_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "rtype_uuid_brand_imei", MD5 = "token")
	public Object commitFeedback(Integer rtype,@RequestParam(required = false,defaultValue = "0") Integer appId, String brand, String model, String vscode, Integer type,
			String imei,String questionDesc,String questionPic, String pid,String uuid, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		if (type == null || type>6) {
			return new RSPE<Object>(-3, "反馈类型不存在！");
		}
		if (StringUtils.isEmpty(questionDesc)) {
			return new RSPE<Object>(-4, "反馈问题信息不能为空！");
		}
		if (!StringUtils.isEmpty(questionPic) && !questionPic.startsWith("http")) {
			return new RSPE<Object>(-5, "反馈图片参数错误！");
		}
		String userid="";
		if (!StringUtils.isEmpty(pid)) {
			String infoByPid = cacheService.getCatDevUserInfoByPid(pid);
			if (StringUtils.isEmpty(infoByPid)) {
				return new RSPE<Object>(-6, "用户不存在！");
			}
			userid=pid;
		}else if (!StringUtils.isEmpty(imei)) {
			return new RSPE<Object>(-7, "设备唯一ID不存在！");
		}else {
			userid=imei;
		}
		final String userid_1=userid;
		Callable<RSPE<String>> result = new Callable<RSPE<String>>() {
			@Override
			public RSPE<String> call() throws Exception {
				try {
					String result = catDevService.commitFeedback(rtype,appId, brand, model,vscode,type,questionDesc,questionPic,userid_1);	
					if (result==null) {
						return new RSPE<String>(0,"提交失败，请重试！");
					}
					return new RSPE<String>(1,"提交成功！");
				} catch (Exception e) {
					// TODO: handle exception
				}
				return new RSPE<String>(0,"提交失败，请重试！");
			}
		};
		return result;
	}
	
	@PostMapping("/get/feedback/history")
	@ApiOperation(value = "查询反馈记录", position = 8, consumes = "application/x-www-form-urlencoded", notes = "查询反馈记录", response = CatUserFeedbackHistoryResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "appId", value = "应用ID(0.九趣猫(默认)、1.淘淘集、2.一陶)", example = "0", required = false, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI,IOS:IDFA", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_appId_imei_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "rtype_uuid_appId_imei", MD5 = "token")
	public Object getFeedbackHistory(Integer rtype,@RequestParam(required = false,defaultValue = "0") Integer appId,String imei, String pid,String uuid, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		String userid="";
		if (!StringUtils.isEmpty(pid)) {
			String infoByPid = cacheService.getCatDevUserInfoByPid(pid);
			if (StringUtils.isEmpty(infoByPid)) {
				return new RSPE<Object>(-6, "用户不存在！");
			}
			userid=pid;
		}else if (StringUtils.isEmpty(imei)) {
			return new RSPE<Object>(-7, "设备唯一ID不存在！");
		}else {
			userid=imei;
		}
		final String userid_1=userid;
		Callable<RSPE<List<CatUserFeedbackHistoryResp>>> result = new Callable<RSPE<List<CatUserFeedbackHistoryResp>>>() {
			@Override
			public RSPE<List<CatUserFeedbackHistoryResp>> call() throws Exception {
				try {
					List<CatUserFeedbackHistoryResp> result = catDevService.getFeedbackHistory(rtype,appId,userid_1);	
					if (result==null) {
						return new RSPE<List<CatUserFeedbackHistoryResp>>(0,"获取失败！");
					}
					return new RSPE<List<CatUserFeedbackHistoryResp>>(result);
				} catch (Exception e) {
					// TODO: handle exception
					log.error("获取反馈信息失败:"+e.getMessage());
				}
				return new RSPE<List<CatUserFeedbackHistoryResp>>(0,"获取失败，请重试！");
			}
		};
		return result;
	}
	
	@PostMapping("/save/deviceToken")
	@ApiOperation(value = "保存用户的deviceToken值", position = 8, consumes = "application/x-www-form-urlencoded", notes = "保存用户的deviceToken值", response = CatDevDeviceTokenRepository.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "应用平台(0.安卓、1.IOS)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户id", example = "862052038380307", required = false, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "devicetoken", value = "设备值", example = "0", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "deviceid", value = "设备id", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(rtype_uuid_devicetoken_time)", example = "8f85345627bf783e6008f84fac27dd18", required = true, dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "rtype_uuid_devicetoken", MD5 = "token")
	public Object saveDeviceToken (Integer rtype,String pid,String devicetoken,String deviceid, String uuid, String token) {
		if (rtype == null || (rtype != 0 && rtype != 1)) {
			return new RSPE<Object>(-2, "应用平台参数错误！");
		}
		if(StringUtils.isEmpty(devicetoken)) {
			return new RSPE<Object>(-3, "devicetoken不能为空");
		}
		if(StringUtils.isEmpty(deviceid)) {
			return new RSPE<Object>(-4, "deviceid不能为空");
		}
		
		Callable<RSPE<String>> result = new Callable<RSPE<String>>() {
			@Override
			public RSPE<String> call() throws Exception {
				try {
					String result = catDevService.saveDeviceToken(rtype, pid, devicetoken, deviceid);	
					if (result==null) {
						return new RSPE<String>(0,"保存失败，请重试！");
					}
					return new RSPE<String>(1,"保存成功！");
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
				return new RSPE<String>(0,"保存失败，请重试！");
			}
		};
		return result;
	}
}
